package com.itheima.controller.mobile;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.vo.OrderMobileVO;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 提交预约
     * @param map
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestBody Map<String,Object> map){
        log.info("提交订单");
        String date = orderService.submitOrder(map);
        boolean success = date.length() < 3;
        if (success){
            return new Result(true, MessageConstant.ORDERSETTING_SUCCESS, date);
        }else {
//            return new Result(false, MessageConstant.ORDERSETTING_FAIL);
            return new Result(false, date);
        }
    }


    @PostMapping("/findById")
    public Result findById(Integer id){
        log.info("查询订单");
        OrderMobileVO orderVo = orderService.findById(id);
        if (orderVo != null){
            return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS, orderVo);
        }else {
            return new Result(false, MessageConstant.QUERY_ORDER_FAIL);
        }
    }
}
